From 1cf9c5aec616076ecc1ed0e3b6e84f8311f292af Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Sat, 18 Mar 2023 21:25:23 +0100
Subject: [PATCH] revert 0d6a75a61e8377d65130eeb59b752cac8e9c9fca

https://github.com/Igalia/WPEBackend-fdo/commit/0d6a75a61e8377d65130eeb59b752cac8e9c9fca

This is reported to potentially cause crashes, so reverting for
now.
---
 src/view-backend-exportable-fdo-egl-private.h | 1 +
 src/view-backend-exportable-fdo-egl.cpp       | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/view-backend-exportable-fdo-egl-private.h b/src/view-backend-exportable-fdo-egl-private.h
index 0e6caba..e19c177 100644
--- a/src/view-backend-exportable-fdo-egl-private.h
+++ b/src/view-backend-exportable-fdo-egl-private.h
@@ -33,6 +33,7 @@ struct wpe_fdo_egl_exported_image {
     EGLImageKHR eglImage { nullptr };
     uint32_t width { 0 };
     uint32_t height { 0 };
+    bool exported { false };
     struct wl_resource* bufferResource { nullptr };
     struct wl_listener bufferDestroyListener;
 };
diff --git a/src/view-backend-exportable-fdo-egl.cpp b/src/view-backend-exportable-fdo-egl.cpp
index 7e74dee..0031222 100644
--- a/src/view-backend-exportable-fdo-egl.cpp
+++ b/src/view-backend-exportable-fdo-egl.cpp
@@ -249,6 +249,8 @@ public:
     {
         if (image->bufferResource)
             viewBackend->releaseBuffer(image->bufferResource);
+        else
+            deleteImage(image);
     }
 
     void releaseShmBuffer(struct wpe_fdo_shm_exported_buffer* buffer)
@@ -275,6 +277,7 @@ private:
 
     void exportImage(struct wpe_fdo_egl_exported_image* image)
     {
+        image->exported = true;
         client->export_fdo_egl_image(data, image);
     }
 
@@ -292,8 +295,6 @@ private:
         image = wl_container_of(listener, image, bufferDestroyListener);
 
         image->bufferResource = nullptr;
-
-        deleteImage(image);
     }
 };
 
-- 
2.39.0

